package org.come.Frame;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.plaf.basic.BasicInternalFrameUI;

import org.come.Jpanel.TeststateJpanel;
import org.come.until.FormsManagement;
import org.come.until.MessagrFlagUntil;
import org.come.until.Music;

import com.tool.tcpimg.UIUtils;

/**
 * @author 郑吉利
 * @date : 2017年11月27日 下午2:11:42
 *
 *       人物状态窗口
 */
public class Teststatejframe extends JInternalFrame implements MouseListener {

    private TeststateJpanel teststateJpanel;
    private int first_x, first_y;

    public static Teststatejframe getTeststatejframe() {

        return (Teststatejframe) FormsManagement.getInternalForm(0).getFrame();

    }

    public Teststatejframe() throws Exception {
        super();
        teststateJpanel = new TeststateJpanel(null);
        this.setBorder(BorderFactory.createEmptyBorder());// 去除内部窗体的边框
        ((BasicInternalFrameUI) this.getUI()).setNorthPane(null);// 去除顶部的边框
        teststateJpanel = new TeststateJpanel(this);
        // this.getContentPane().add(teststateJpanel);
        this.setContentPane(teststateJpanel);
        this.setBounds(610, 150, 400, 300);
        // this.add(teststateJpanel);
        this.pack();
        // this.setLocationRelativeTo(null);
        setBackground(UIUtils.Color_BACK);
        this.setVisible(false);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.addMouseListener(this);
        this.addMouseMotionListener(new MouseMotionListener() {

            @Override
            public void mouseMoved(MouseEvent e) {
                if (MessagrFlagUntil.ImgFlagImg.equals(MessagrFlagUntil.MOUSE13)) {
                    MessagrFlagUntil.setMouse(MessagrFlagUntil.MOUSE1);
                }
            }

            @Override
            public void mouseDragged(MouseEvent e) {
                if (isVisible()) {
                    int x = e.getX() - first_x;
                    int y = e.getY() - first_y;
                    setBounds(x + getX(), y + getY(), getWidth(), getHeight());
                }

            }
        });

    }

    public TeststateJpanel getTeststateJpanel() {
        return teststateJpanel;
    }

    public void setTeststateJpanel(TeststateJpanel teststateJpanel) {
        this.teststateJpanel = teststateJpanel;
    }

    @Override
    public void mouseClicked(MouseEvent e) {

    }

    @Override
    public void mousePressed(MouseEvent e) {
        // 关闭音效
        Music.addyinxiao("关闭窗口.mp3");
        // 打开了窗体
        if (e.isMetaDown()) {// 检测鼠标右键单击
            FormsManagement.HideForm(0);
        } else {
            FormsManagement.Switchinglevel(0);
        }

        this.first_x = e.getX();
        this.first_y = e.getY();

    }

    @Override
    public void mouseReleased(MouseEvent e) {

    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }

    public int getFirst_x() {
        return first_x;
    }

    public void setFirst_x(int first_x) {
        this.first_x = first_x;
    }

    public int getFirst_y() {
        return first_y;
    }

    public void setFirst_y(int first_y) {
        this.first_y = first_y;
    }

}
